<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-row>
        <el-col :span="6">
          <el-form-item label="笔记内容">
            <el-input v-model="dataForm.key" placeholder="内容" clearable></el-input>
          </el-form-item>
        </el-col>        
        <el-col :span="6">
          <el-form-item label="状态">
            <el-select v-model="statusId" placeholder="请选择" clearable>
              <el-option
                v-for="item in statusList"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="发布时间">
            <el-date-picker
              v-model="time"
              type="daterange"
              range-separator="至"
              value-format="yyyy-MM-dd"
              start-placeholder="开始日期"
              end-placeholder="结束日期">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <!-- <el-button v-if="isAuth('biz:publishExperts:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
        <el-button v-if="isAuth('biz:publishExperts:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button> -->
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="id"
        header-align="center"
        align="center"
        label="序号">
      </el-table-column>
      <el-table-column
        prop="titlePicture"
        header-align="center"
        align="center"
        label="头图">
        <template slot-scope="scope">
          <img  :src="scope.row.titlePicture" alt="" style="width: 100px;">
        </template>
      </el-table-column>
      <el-table-column
        prop="publishName"
        header-align="center"
        align="center"
        label="客人昵称">
      </el-table-column>
      <!-- <el-table-column
        prop="brandId"
        header-align="center"
        align="center"
        label="品牌id">
      </el-table-column>
      <el-table-column
        prop="categoryId"
        header-align="center"
        align="center"
        label="分类id">
      </el-table-column>
      <el-table-column
        prop="sku"
        header-align="center"
        align="center"
        label="货号">
      </el-table-column>
      <el-table-column
        prop="color"
        header-align="center"
        align="center"
        label="颜色">
      </el-table-column>
      <el-table-column
        prop="size"
        header-align="center"
        align="center"
        label="尺寸">
      </el-table-column>
      <el-table-column
        prop="sex"
        header-align="center"
        align="center"
        label="性别">
      </el-table-column> -->
      <el-table-column
        prop="article"
        header-align="center"
        align="center"
        label="内容" show-overflow-tooltip>
      </el-table-column>
      <!-- <el-table-column
        prop="descJson"
        header-align="center"
        align="center"
        label="详情">
      </el-table-column> -->
      <!-- <el-table-column
        prop="location"
        header-align="center"
        align="center"
        label="定位">
      </el-table-column> -->
      <el-table-column
        prop="createdAt"
        header-align="center"
        align="center"
        label="创建时间">
      </el-table-column>
      <el-table-column
        prop="updatedAt"
        header-align="center"
        align="center"
        label="更新时间">
      </el-table-column>
      <!-- <el-table-column
        prop="deletedAt"
        header-align="center"
        align="center"
        label="删除状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.deletedAt==null"
              type="success"
              disable-transitions>未删除</el-tag>
          <el-tag v-else
              type="danger"
              disable-transitions>已删除</el-tag>
          </template>
      </el-table-column>
      <el-table-column
        prop="checkFlag"
        header-align="center"
        align="center"
        label="审核状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.checkFlag==1"
            type="success"
            disable-transitions>已审核</el-tag>
          <el-tag v-else-if="scope.row.checkFlag==0"
            type="primary"
            disable-transitions>未审核</el-tag>
          <el-tag v-else="scope.row.checkFlag==2"
            type="danger"
            disable-transitions>审核失败</el-tag>
        </template>
      </el-table-column> -->
      <el-table-column
        prop="checkFlag"
        header-align="center"
        align="center"
        label="状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.deletedAt!=null"
            type="success"
            disable-transitions>已删除</el-tag>
          <el-tag v-else-if="scope.row.checkFlag==1&&scope.row.deletedAt==null"
            type="primary"
            disable-transitions>已审核</el-tag>
          <el-tag v-else-if="scope.row.checkFlag==0&&scope.row.deletedAt==null"
            type="primary"
            disable-transitions>未审核</el-tag>
          <el-tag v-else="scope.row.checkFlag==2&&scope.row.deletedAt==null"
            type="danger"
            disable-transitions>审核失败</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <!-- <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
          <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button> -->
          <el-button v-if="scope.row.checkFlag==0&&scope.row.deletedAt==null" type="text" size="small" @click="checkNotesHandle(scope.row.id)">审核</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
  import AddOrUpdate from './publishExperts-add-or-update'
  export default {
    data () {
      return {
        statusId: '',
        time: [],
        dataForm: {
          key: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false,
        statusList:[{
            "id":0,
            "name":"未审核"
        },{
            "id":1,
            "name":"已审核"
        },{
            "id":2,
            "name":"已删除"
        },{
            "id":3,
            "name":"审核失败"
        }
        ],
      }
    },
    components: {
      AddOrUpdate
    },
    activated () {
      this.getDataList()
    },
    methods: {
      checkNotesHandle(id) {
        let query = {id: id};
        this.$router.push({
            name: 'publishExpertsCheck',
            query: query
        });
      },
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/biz/publishExperts/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'key': this.dataForm.key,
            'minDt':this.time!=undefined&&this.time.length == 2 ?this.time[0] + " 00:00:00":"",
            'maxDt':this.time!=undefined&&this.time.length == 2 ?this.time[1] + " 23:59:59":"",
            'state':this.statusId
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/biz/publishExperts/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      }
    }
  }
</script>
